﻿namespace MapleRock.P2PEmulator.RGR
{
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Linq;
  using System.Text;

  internal sealed class RgrExperiment
  {
    public const int RunsPerSample = 5;

    private List<ModelSampleParams> sampleParams = null;

    public RgrExperiment(
      int variableParameterIndex, 
      int peersNumberIndex,
      int messageLossProbIndex,
      int dimensionsIndex,
      int maxPeerLinksIndex)
    {
      this.sampleParams = ModelSampleParams.GetSampleParams(
        ExperimentPage.PeersNumber,
        ExperimentPage.MessageLossProb,
        ExperimentPage.Dimensions,
        ExperimentPage.MaxPeerLinks,
        variableParameterIndex,
        peersNumberIndex,
        messageLossProbIndex,
        dimensionsIndex,
        maxPeerLinksIndex);

      this.Samples = new RgrExperimentSample[this.sampleParams.Count];
    }

    public RgrExperimentSample[] Samples { get; private set; }

    public void Go()
    {
      ExperimentLog.Instance.LogEvent("{0} samples to run", this.Samples.Length);

      for(var i = 0; i < this.Samples.Length; ++ i)
      {
        ExperimentLog.Instance.LogEvent("Running sample {0}/{1}", i + 1, this.Samples.Length);  

        Debug.Assert(this.Samples[i] == null, "this.Samples[i] == null");
        this.Samples[i] = new RgrExperimentSample(
          RunsPerSample, 
          this.sampleParams[i]);
        this.Samples[i].Go();
      }

      ModelOutputFile.Instance.EndExperiment();
    }
  }
}
